<h1><?php echo $fund['name'] ?></h1>
<ul id="breadcrumb">
	<li>บัญชีแยกประเภท</li>			
</ul>
<div id="content">
	<div class="search">
		<form method="get">
		<label>บัญชี  </label><?php echo form_dropdown('account_id',get_option('id','name','accounts','fund_id = '.$fund['id'].' order by id asc'),$account_id) ?> 
		&nbsp;&nbsp;<label>ปีงบประมาณ </label><?php echo form_dropdown('year', get_year_option('2550'),$year+543); ?>
		&nbsp;&nbsp;<label>เดือน </label><?php echo form_dropdown('month', get_month(),$month); ?>
		<?php if(level_data('view')): ?>
		&nbsp;&nbsp;<label>หน่วยงาน </label><?php echo form_dropdown('agency_id', get_agency_option($fund['id']),$agency_id,'','ทั้งหมด'); ?>
		<?php endif; ?>
			&nbsp;&nbsp;<input type="submit" value="<?php echo lang('search'); ?>" class="button" />
		</form>
	</div>
	<div class="head">
		<p><?php echo $fund['name'] ?></p>
		<p>บัญชีแยกประเภท - <?php echo get_one('name','accounts','id',$account_id) ?></p>
		<p>ประจำ<?php echo 'ปีงบประมาณ '.($year+543) ?> เดือน <?php echo month($month) ?></p>
	</div>
<table class="list">
	<tr>
		<th width="100">วัน เดือน ปี</th>
		<th width="100">เลขที่เอกสาร</th>
		<th width="500">รายการ</th>
		<th width="100">หน้าบัญชี</th>
		<th width="100">ยอดยกมา</th>
		<th width="100">เดบิต</th>
		<th width="100">เครดิต</th>
		<th width="100">คงเหลือ</th>
	</tr>
	<?php $date = ""; ?>
	<?php $number = ""; ?>
	<?php $month = 0; ?>
	<?php $voucher_date = 0; ?>
	<?php $cr_month = 0; ?>
	<?php $dr_month = 0; ?>
	<?php $sum_month = 0; ?>
	<?php if($result): ?>
	<? foreach($result as $key => $item): ?>
	<?php if(($month<>date('n',mysql_to_unix($item['voucher_date'])))&&($key<>0)): ?>
	
	<tr>
		<td></td><td></td><td>รวม <?php echo db_to_my(mysql_to_unix($voucher_date)) ?></td><td></td><td class="num"><?php echo number_format($sum_month,2) ?></td><td class="num"><?php echo number_format($dr_month,2) ?></td><td class="num"><?php echo number_format($cr_month,2) ?></td><td class="num"><?php echo number_format(($sum_month+$dr_month)-$cr_month,2) ?></td>
	</tr>
	<tr>
		<td></td><td></td><td>รวมแต่ต้นปี </td><td></td><td class="num"><?php echo number_format($sum_month,2) ?></td><td class="num"><?php echo number_format($dr,2) ?></td><td class="num"><?php echo number_format($cr,2) ?></td><td class="num"><?php echo number_format($sum,2) ?></td>
	</tr>
	<?php $cr_month = 0; ?>
	<?php $dr_month = 0; ?>
	<?php $sum_month = 0; ?>
	<?php endif; ?>
	<?php if($key==0): ?>
	<tr>
		<td class="center"><?php echo mysql_to_date($item['voucher_date'],TRUE)?></td>
		<td class="center"><?php echo $item['number']?></td>
		<td>ยอดยกมา</td>
		<td></td>
		<td class="num"><?php echo number_format($sum,2) ?></td>
		<td></td>
		<td></td>
		<td class="num"><?php echo number_format($sum,2)?></td>
	</tr>
	<?php $sum_month = $sum; ?>
	<?php endif; ?>
	<tr>
		<?php ($item['type']=="dr")?$sum -= $item['real_price']:$sum += $item['real_price']?>
		<?php ($item['type']=="dr")?$cr += $item['real_price']:$dr += $item['real_price']?>
		<?php ($item['type']=="dr")?$cr_month += $item['real_price']:$dr_month += $item['real_price']?>
		<?php if($date==$item['voucher_date']): ?>
		<td></td>
		<?php if($number<>$item['number']): ?>
		<td class="center"><?php echo $item['number']?></td>
		<?php else: ?>
		<td></td>
		<?php endif; ?>
		<?php else: ?>
			<?php if($key==0): ?>
			<td></td>
		<td></td>
			<?php else: ?>
		<td class="center"><?php echo mysql_to_date($item['voucher_date'],TRUE)?></td>
		<td class="center"><?php echo $item['number']?></td>
		<?php endif; ?>
		<?php endif; ?>
		<td><?php echo $item['account_name']?></td>
		
		<td class="center"><?php echo $item['account_code']?></td>
		<td></td>
		<td class="num"><?php echo ($item['type']=="cr")?number_format($item['real_price'],2):''?></td>
		<td class="num"><?php echo ($item['type']=="dr")?number_format($item['real_price'],2):''?></td>
		<td class="num"><?php echo number_format($sum,2)?></td>
		<?php $month = date('n',mysql_to_unix($item['voucher_date'])) ?>
		<?php $voucher_date = $item['voucher_date'] ?>
		<?php $date = $item['voucher_date']; ?>
		<?php $number = $item['number']; ?>
	</tr>
	<? endforeach; ?>
	<tr>
		<td></td><td></td><td>รวม <?php echo db_to_my(mysql_to_unix($item['voucher_date'])) ?></td><td></td><td class="num"><?php echo number_format($sum_month,2) ?></td><td class="num"><?php echo number_format($dr_month,2) ?></td><td class="num"><?php echo number_format($cr_month,2) ?></td><td class="num"><?php echo number_format(($sum_month+$dr_month)-$cr_month,2) ?></td>
	</tr>
	<tr>
		<td></td><td></td><td>รวมแต่ต้นปี </td><td></td><td class="num"><?php echo number_format($sum_month,2) ?></td><td class="num"><?php echo number_format($dr,2) ?></td><td class="num"><?php echo number_format($cr,2) ?></td><td class="num"><?php echo number_format($sum,2) ?></td>
	</tr>
	<?php else: ?>
	<tr>
		<td colspan="8" class="center">- ไม่มีข้อมูล -</td>
	</tr>
	<?php endif; ?>
</table>
</div>